package com.DataBase.IDAOImpl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.DataBase.DBCPool.Pool;
import com.DataBase.IDAO.UserManager;
import com.Protocal.User.ContactInfo_Request;
import com.Protocal.User.ContactInfo_Response;
import com.Protocal.User.Login_Request;
import com.Protocal.User.Login_Response;
import com.Protocal.User.Logout_Request;
import com.Protocal.User.Logout_Response;

public class UserManagerImpl implements UserManager {

	private 	Pool	m_Pool = Pool.getInstance();
	public ContactInfo_Response doContactInfo(ContactInfo_Request cr) {
		// TODO Auto-generated method stub
		return null;
	}

	public Logout_Response doLogout(Logout_Request lor) {
		// TODO Auto-generated method stub
		return null;
	}

	public Login_Response validate(Login_Request lir) {
		// TODO Auto-generated method stub
		String  userid=lir.getUserid();
		String  password=lir.getPassword();
		Login_Response  lr=new Login_Response();
		System.out.println("35###");
		try{
			Connection conn=m_Pool.getConnection();
			if(!conn.isClosed())
				System.out.println(userid+"\n"+password+"\n"+"successed connect to the Datebase");
			
			Statement statement=conn.createStatement();
			String sql="select * from user where userid='"+userid+"'";
			System.out.println("43###");
			ResultSet rs = statement.executeQuery(sql);
			System.out.println("45###");
			if(rs.next()) {
				System.out.println("47###");
				if(rs.getString("password").equals(password)){
					lr.setLogin_result("s");
					System.out.println(rs.getString("name"));
				}
				else{
				    lr.setLogin_result("f");
				}
			}
			rs.close();
			statement.close();
			m_Pool.freeConnection(conn);
		}catch(SQLException e2){
			e2.printStackTrace();
		}
		catch(Exception e3){
			e3.printStackTrace();
		}
		return lr;
	}

}
